#include "Tank.h"
#include <assert.h>

void tankInit(Tank* t)
{
    t->tank_x=5;
    t->tank_y=14;
    t->tank_vie=3;
    t->tank_projectile=0;
    t->tank_direction=3;
    t->tank_temp=1;
    t->tank_forcetir=0;
    t->tank_baseok=0;
}

int tankGetTemp(const Tank* t)
{
    return t->tank_temp;
}

void tankSetTemp(Tank* t,int n)
{
    t->tank_temp=n;
}

void tankSetVie(Tank* t,int n)
{
    t->tank_x=n;
}

int tankGetX(const Tank* t)
{
    return t->tank_x;
}

void tankSetProjectile(Tank* t,int nb)
{
    t->tank_projectile=nb;
}

int tankGetY(const Tank* t)
{
    return t->tank_y;
}

int tankGetDirection(const Tank* t)
{
    return t->tank_direction;
}

int tankGetVie(const Tank* t)
{
    return t->tank_vie;
}

void tankSetDirection(Tank* t,int nb)
{
    assert(nb>=0);
    assert(nb<4);
    t->tank_direction=nb;
}

void tankHaut(Tank* t,const Terrain* ter)
{
    if(t->tank_direction != 3)
    {
        t->tank_direction=3;
    }
    else if(terPositionValide(ter,t->tank_x,t->tank_y-1)&& t->tank_direction==3)
    {
        t->tank_y--;
    }
}

void tankBas(Tank* t,const Terrain* ter)
{
    if(t->tank_direction != 2)
    {
        t->tank_direction=2;
    }
    else if(terPositionValide(ter,t->tank_x,t->tank_y+1)&& t->tank_direction==2)
    {
        t->tank_y++;
    }
}

void tankGauche(Tank* t,const Terrain* ter)
{
    if(t->tank_direction != 0)
    {
        t->tank_direction=0;
    }
    else if(terPositionValide(ter,t->tank_x-1,t->tank_y)&& t->tank_direction==0)
    {
        t->tank_x--;
    }
}

void tankDroit(Tank* t,const Terrain* ter)
{
    if(t->tank_direction != 1)
    {
        t->tank_direction=1;
    }
    else if(terPositionValide(ter,t->tank_x+1,t->tank_y)&& t->tank_direction==1)
    {
        t->tank_x++;
    }
}

void tankTestRegression()
{
    Tank t;
    tankInit(&t);
    assert(t.tank_x==0);
    assert(t.tank_y==0);
    assert(t.tank_vie==3);
}





